package spring.aop;

import java.util.Arrays;
import java.util.List;

import javax.xml.ws.soap.Addressing;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LogginAspect {

	/**
	 * 在spring.aop接口的每一个实现类方法之前执行一段代码
	 */
	@Before("execution(public int spring.aop.ArithmeticCalculatorImpl.*(..))")
	public void before(JoinPoint joinPoint){
		String methodName=joinPoint.getSignature().getName();
		List<Object> args=Arrays.asList(joinPoint.getArgs());
		System.out.println("The method begins" +methodName +"begins with"+args);
	}
	
	/**
	 * 方法执行之后的代码，无论该方法是否出现异常
	 * @param joinPoint
	 */
	@After("execution(public int spring.aop.ArithmeticCalculatorImpl.*(..))")
	public void afterMehtod(JoinPoint joinPoint){
		String methodName=joinPoint.getSignature().getName();
		System.out.println("The Method "+methodName+" end");
	}
	
	
	@AfterReturning(value="execution(public int spring.aop.ArithmeticCalculatorImpl.*(..))",
			returning="result")
	public void afterReturn(JoinPoint joinPoint,Object result){
		String methodName=joinPoint.getSignature().getName();
		System.out.println("The Method "+methodName+" end with "+result);
	}
}
